<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/4/14
 * Time: 22:01
 */

namespace Home\Model;

use Think\Model;

class UserAddModel extends BaseModel
{
    // 数据表名（不包含表前缀）
    protected $tableName = 'user';

    /**
     * 判断是否实名认证
     * @param Integer $u_id 用户ID
     * @return boolean
    **/
    public function getRealName($u_id)
    {
        $res=$this->where("u_id=$u_id")->getField('u_status');
        if ($res==2) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 根据用户ID查询用户状态
     * @param Integer $u_id 用户ID
     * @return u_status
    **/
    public function checkStatus($u_id)
    {
        return $this->where("u_id=$u_id")->getField('u_status');
    }
    /**
     * 根据$real_number查询是否存在
     * @return boolean
    **/
    public function getRealNumber($real_number)
    {
        $realNumber= $this->where("real_number LIKE $real_number")->select();
        if ($realNumber==false) {
            return false;
        } else {
            return true;
        }
    }
    /**
     * 实名信息添加
     * @param Integer $u_id 用户ID
     * @param String $real_number 真实名称
     * @param String $user_ID 身份证ID
     * @return boolean
    **/
    public function realInfoSave($u_id, $real_name, $real_number)
    {
        $data['real_name']=$real_name;
        $data['real_number']=$real_number;
        $res=$this->where("u_id=$u_id")->save($data);
        if ($res>0) {
            $this->where("u_id=$u_id")->setField('u_status', 3);
            return true;
        } else {
            return false;
        }
    }
    /**
     * 银行卡认证
     * @param Integer $u_id 用户ID
     * @param String $bank 银行名称
     * @param String $bank_number 银行卡账号
     * @return boolean
    **/
    public function bankSave($u_id, $bank, $bank_number)
    {
        $data['bank']=$bank;
        $data['bank_number']=$bank_number;
        $res=$this->where("u_id=$u_id")->save($data);
        if ($res>0) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 查询用户Email
     * @param String $u_email 用户邮箱
     * @return boolean
     **/
    public function getUserEmail($u_email)
    {
        $res= $this->where("u_email LIKE '$u_email'")->select();
        if ($res==false) {
            return false;
        } else {
            return true;
        }
    }
    /**
     * 用户注册
     * @param String $u_name  用户姓名
     * @param String $u_email  用户邮箱
     * @param String $u_pwd  用户密码
     * @param Integer $u_age  用户年龄
     * @param Integer $u_sex  用户性别
     * @param Integer $u_type_id  用户类型ID
     * @param Integer $u_tel  用户电话
     * @param String $u_address  用户地址
     * @param Integer $u_postcode  用户邮编
     * @param String $pictrueName  用户图片
     * @param String $u_regdate   用户注册时间
     * @param String $u_status 认证状态
     * @return boolean
     **/
    public function UserRegister($u_name, $u_email, $u_pwd, $u_age, $u_sex=1, $u_type_id, $u_tel, $u_address, $u_postcode, $pictrueName)
    {
        $data['u_name']=$u_name;
        $data['u_email']=$u_email;
        $data['u_pwd']=myMd5($u_pwd);
        $data['u_age']=$u_age;
        $data['u_sex']=$u_sex;
        $data['u_type_id']=$u_type_id;
        $data['u_tel']=$u_tel;
        $data['u_address']=$u_address;
        $data['u_postcode']=$u_postcode;
        $data['u_pic']=$pictrueName;
        $data['u_regdate']=time();
        $data['u_del']=1;
        $res=$this->add($data);
        if ($res>0) {
            return true;
        } else {
            return false;
        }
    }
}
